package com.hzp.lolnews.ui.discovery.view;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;

import com.hzp.lolnews.R;
import com.hzp.lolnews.base.BaseFragment;
import com.hzp.lolnews.bean.DiscoveryContent;
import com.hzp.lolnews.bean.DiscoveryNav;
import com.hzp.lolnews.configs.Configs;
import com.hzp.lolnews.ui.discovery.presenter.DiscoveryPresenter;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoveryFragment extends BaseFragment implements IDiscoveryContent {


    private XRecyclerView headRecycler;
    private DiscoveryHeadAdapter headAdapter;
    private XRecyclerView mRecyclerView;
    private DiscoveryContentAdapter contentAdapter;

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        headRecycler = (XRecyclerView) view.findViewById(R.id.dis_headRecycler);
        mRecyclerView = (XRecyclerView) view.findViewById(R.id.dis_contentRecycler);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(getFActivity(), 4);
        headRecycler.setLayoutManager(gridLayoutManager);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getFActivity(),LinearLayoutManager.VERTICAL,false);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        DiscoveryPresenter presenter = new DiscoveryPresenter(this);
        presenter.loadData();
        headAdapter = new DiscoveryHeadAdapter();
        contentAdapter = new DiscoveryContentAdapter(getFActivity());

        headRecycler.setAdapter(headAdapter);
        mRecyclerView.setAdapter(contentAdapter);

    }

    @Override
    public void initView() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_discovery;
    }

    @Override
    public String[] getPath() {
        return Configs.urlDis;
    }

    @Override
    public void addDiscoveryNavi(List<DiscoveryNav> list) {
        if (list != null) {
            headAdapter.setData(list);
            Log.i("TAG", "addDiscoveryNavi:----------------------------> " + list);
        }
    }

    @Override
    public void addDiscoveryContent(List<DiscoveryContent> list) {
        if (list != null) {
            contentAdapter.setData(list);
        }
    }


    @Override
    public void showLoadFailMsg(String msg, Throwable e) {
        Log.i("TAG", "showLoadFailMsg:----------------------------+ " + msg);
    }

    @Override
    public void showLoadingView() {

    }

    @Override
    public void hideLoadingView() {

    }
}
